/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package basket;

import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.imageio.ImageIO;

/**
 *
 * @author Windows7
 */
public class basket {
    
    private String imagePng = "images/ro.png";
    
    private int dx;
    private int dy;
    private int x;
    private int y;
    private BufferedImage image;
    private int right;
    
    private boolean visible;
    
    private int h;
    private int w;
    
    //private ArrayList missiles;
    
    private final int craft_size = 60;
    
    public basket(int right)
    {
        this.x = 300;
        this.y = 500;
        this.right = right;
        //missiles = new ArrayList();
        try
        {
            image = ImageIO.read(new File(imagePng));
            this.h = image.getHeight();
            this.w = image.getWidth();
            this.visible = true;
        }
        catch(IOException e)
        {
            
        }
        
        
    }
    
    public void move()
    {
        x+= dx;
        y+= dy;
        if (x < 1) 
        {
            x = 1;
        }
        
        if (x > right - 70) 
        {
            x = right - 70;
        }
        

    }

    /**
     * @return the x
     */
    public int getX() {
        return x;
    }

    /**
     * @return the y
     */
    public int getY() {
        return y;
    }
    
    /**
     * @return the image
     */
    public BufferedImage getImage() {
        return image;
    }
    
     /**
     * @return the missiles
     */
    /*public ArrayList getMissiles() {
        return missiles;
    }*/
        /**
     * @return the visible
     */
    public boolean isVisible() {
        return visible;
    }
    
    public synchronized void draws(Graphics2D grap)
    {
        /*AffineTransform t = new AffineTransform();
        t.translate(this.x, this.y);
        t.scale(1, 1);*/
        grap.drawImage(this.image,this.x, this.y, null);
    }

    /**
     * @param visible the visible to set
     */
    public void setVisible(boolean visible) {
        this.visible = visible;
        
    }
    
    public Rectangle getBounds()
    {
        return new Rectangle(this.x, this.y, this.w, this.h);
    }
    
    public void fire() throws IOException
    {
        //missiles.add(new missile(x + this.craft_size, y));
    }
    
    
    public void keyPressed(KeyEvent e) throws IOException
    {
        int key = e.getKeyCode();
        
        /*if (key == KeyEvent.VK_SPACE) {
            fire();
        }*/
        
        if (key == KeyEvent.VK_LEFT) {
            dx = -3;
        }

        if (key == KeyEvent.VK_RIGHT) {
            dx = 3;
        }

        /*if (key == KeyEvent.VK_UP) {
            dy = -1;
        }

        if (key == KeyEvent.VK_DOWN) {
            dy = 1;
        }*/
    }
     public void keyReleased(KeyEvent e) {
        int key = e.getKeyCode();

        if (key == KeyEvent.VK_LEFT) {
            dx = 0;
        }

        if (key == KeyEvent.VK_RIGHT) {
            dx = 0;
        }

        /*if (key == KeyEvent.VK_UP) {
            dy = 0;
        }

        if (key == KeyEvent.VK_DOWN) {
            dy = 0;
        }*/
    }
    
}
